var express=require('express');
var app = express();

app.all('*',function(req,res,next){
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
})
app.use(express.static('static'));

app.get("/",function(req,res){
    res.send('Hello World')
});

//测试
var test = require('./test/TestServer')
app.use('/api/test',test)



app.use(function(req,res,next){
    res.status(404).send('This Request is Not Found!');
});
app.use(function(err,req,res,next){
    console.error(err.stack)
    res.status(500).send('This Request Found An Error!');
});





var server = app.listen(3000,function(){

    var host = server.address().address;
    var port = server.address().port;
    host = host === '::'?'127.0.0.1':host;

    console.log('App listening at http://%s:%s', host, port);
})